package service

import (
	"context"
	__ "user-server/basic/proto"
	"user-server/handler/model"
)

// server is used to implement helloworld.GreeterServer.
type Server struct {
	__.UnimplementedUserServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) MembershipResp(_ context.Context, in *__.MembershipReq) (*__.MembershipResp, error) {

	membership := model.Membership{
		UserId:     int(in.UserId),
		Membership: in.Membership,
		Duration:   in.Duration,
	}

	if err := membership.CreateMembership(); err != nil {
		return &__.MembershipResp{
			Code: 400,
			Msg:  "会员等级管理创建失败",
		}, nil
	}

	return &__.MembershipResp{
		Code: 200,
		Msg:  "会员等级管理创建成功",
	}, nil
}
